package responsitory;

import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import bean.HuiFuBean;
import bean.HuiFuTwoBean;
import bean.LuntanIndexPageBean;
import bean.SignInShowBean;
import bean.TopicDetailBean;
import bean.TopicListlBean;
import bean.login_bean.PersonDataBean;
import interfaces.ILunTanInterface;
import util.volley.BaseErrorListener;
import util.volley.BaseNetRepository;
import util.volley.BaseSuccessReqListener;
import util.volley.ByJsonRequest;
import util.volley.ICompleteListener;

/**
 * 帖子
 */
public class LunTanResponsitory extends BaseNetRepository implements ILunTanInterface<PersonDataBean> {
    final String APIKEY = "100";
    //帖子首页
    public  static  final  String indexPage="By_Bbs_index";
    //帖子详情
    public  static  final  String topicDetail="By_Bbs_detail";
    //帖子列表
    public  static  final  String liebiao="By_Bbs_listPost";
    //帖子点赞
    public  static  final  String zan="By_Bbs_like";
    //帖子回复列表
    public  static  final  String huifuList="By_Bbs_listReply";
    //发帖
    public  static  final  String fabiao="By_Bbs_addPost";
    //我的帖子
    public  static  final  String my_tiezi="By_Bbs_myPost";
    //删除我的帖子
    public  static  final  String delete_tiezi="By_Bbs_delPost";
    //转发帖子
    public  static  final  String zhuanfa_tiezi="By_Bbs_repeat";
    //帖子回复
    public  static  final  String huifu_tiezi="By_Bbs_addReply";

    //签到详情
    public  static  final  String signDetail="By_Bbs_signDetail";

    //签到动作
    public  static  final  String sign="By_Bbs_sign";

    //删除自己的评论
    public  static  final  String delete_pinglun="By_Bbs_delReply";

    public LunTanResponsitory(ICompleteListener ICompleteListener){
        super(ICompleteListener);
    }


    @Override
    public void indexPage(int size, String uid) {
        Type type = new TypeToken<LuntanIndexPageBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("size", size);
        map.put("uid", uid);
        map.put("default", "10");
        (new ByJsonRequest.Builder<LuntanIndexPageBean>())
                .setTypeVerParamsAndReturnClass(indexPage, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<LuntanIndexPageBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void topicDetail(int id, String uid) {
        Type type = new TypeToken<TopicDetailBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("uid", uid);

        (new ByJsonRequest.Builder<TopicDetailBean>())
                .setTypeVerParamsAndReturnClass(topicDetail, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<TopicDetailBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void topicList(int page, int size, String uid, String kword) {
        Type type = new TypeToken<TopicListlBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("size", size);
        map.put("uid", uid);
        map.put("kword", kword);

        (new ByJsonRequest.Builder<TopicListlBean>())
                .setTypeVerParamsAndReturnClass(liebiao, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<TopicListlBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void dianzan(String uid, String pid, String rid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pid", pid);
        map.put("rid", rid);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(zan, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void topicHuiFuList(String uid, String pid, String rid, int page, int size) {
        Type type = new TypeToken<HuiFuBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pid", pid);
        map.put("rid", rid);
        map.put("page", page);
        map.put("size", size);

        (new ByJsonRequest.Builder<HuiFuBean>())
                .setTypeVerParamsAndReturnClass(huifuList, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HuiFuBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void topicHuiFuListTwo(String uid, String pid, String rid, int page, int size) {
        Type type = new TypeToken<HuiFuTwoBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pid", pid);
        map.put("rid", rid);
        map.put("page", page);
        map.put("size", size);

        (new ByJsonRequest.Builder<HuiFuTwoBean>())
                .setTypeVerParamsAndReturnClass(huifuList, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HuiFuTwoBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void fatie(String uid, String title, String content, String img, String reply_limit, String top, String app) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("title", title);
        map.put("content", content);
        map.put("img", img);
        map.put("reply_limit", reply_limit);
        map.put("top", top);
        map.put("app", app);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(fabiao, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void myTieZi(String uid, int page, int size) {
        Type type = new TypeToken<TopicListlBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("page", page);
        map.put("size", size);

        (new ByJsonRequest.Builder<TopicListlBean>())
                .setTypeVerParamsAndReturnClass(my_tiezi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<TopicListlBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void deleteTieZi(String uid, String pid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pid", pid);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(delete_tiezi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void zhuanfaTieZi(String uid, String content, String reply_limit, String repeat_id, String app) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("content", content);
        map.put("reply_limit", reply_limit);
        map.put("repeat_id", repeat_id);
        map.put("app", app);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(zhuanfa_tiezi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void huifuTieZi(String uid, String pid, String rid, String to_uid, String content, String img, String app) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pid", pid);
        map.put("rid", rid);
        map.put("to_uid", to_uid);
        map.put("content", content);
        map.put("img", img);
        map.put("app", app);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(huifu_tiezi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void SignInShow(String uid) {
        Type type = new TypeToken<SignInShowBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);


        (new ByJsonRequest.Builder<SignInShowBean>())
                .setTypeVerParamsAndReturnClass(signDetail, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<SignInShowBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void SignIn(String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);


        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(sign, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    @Override
    public void deleteMyHuiFu(String uid, int rid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("rid", rid);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(delete_pinglun, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
